package com.leagueoflegends.controller;

import com.github.pagehelper.PageInfo;
import com.leagueoflegends.bean.Champion;
import com.leagueoflegends.bean.ChampionPassive;
import com.leagueoflegends.bean.ChampionSpell;
import com.leagueoflegends.service.ChampionSpellManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Controller
public class ChampionSpellManageController {

    @Autowired
    ChampionSpellManageService championSpellManageService;

    @ResponseBody
    @GetMapping(value = "/selectSpell/{championId}")
    public List<ChampionSpell> selectSpell(@PathVariable("championId") int championId) {
        return championSpellManageService.selectSpell(championId);
    }

    @ResponseBody
    @RequestMapping(value = "/selectChampionSpell")
    public PageInfo<Champion> selectChampionSpell(
            @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
            @RequestParam(value = "pageSize", defaultValue = "12") int pageSize,
            @RequestParam(value = "val", defaultValue = "1") int val,
            @RequestParam(value = "find", defaultValue = "") String find
    ) {
        List<Champion> list = championSpellManageService.selectChampionSpell(pageNum, pageSize, val, find);
        return PageInfo.of(list);
    }

    @ResponseBody
    @RequestMapping(value = "/selectNoHaveSpell")
    public List<Champion> selectNoHaveSpell() {
        return championSpellManageService.selectNoHaveSpell();
    }

    @ResponseBody
    @RequestMapping(value = "/selectDeletedChampion")
    public List<Champion> selectDeletedChampion() {
        return championSpellManageService.selectDeletedChampion();
    }

    // 更新
    @ResponseBody
    @PutMapping("/updateChampionSpell")
    public String update(@RequestBody ChampionSpell spell) {
        championSpellManageService.update(spell);
        return "200";
    }

    //添加
    @ResponseBody
    @PostMapping("/addChampionSpell")
    public String insert(@RequestBody ChampionSpell spell) {
        championSpellManageService.insert(spell);
        return "200";
    }

    //删除
    @ResponseBody
    @DeleteMapping("/deleteChampionSpellById/{id}")
    public String delete(@PathVariable Integer id) {
        championSpellManageService.delete(id);
        return "200";
    }
}
